﻿/* 
* Copyright (c) 2010, The University of Texas at Austin
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, 
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, 
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, 
* this list of conditions and the following disclaimer in the documentation and/or other materials 
* provided with the distribution.
*
* Neither the name of The University of Texas at Austin nor the names of its contributors may be 
* used to endorse or promote products derived from this software without specific prior written 
* permission.
* 
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

using System;
using System.Windows;

namespace Bio.Views.Structure.Editor.Internal.Rendering.Primitives
{
    public class NucleotideVector
    {
        public NucleotideVector()
        {
            NucleotideCenter = new Point(0, 0);
            NextNucleotide = new Point(0, 0);
            Distance = 0.0;
            RayAngle = 0.0;
            Center = new Point(0, 0);
        }

        public NucleotideVector(Point ntCenter, Point nextNucleotideCenter, Point prevNucleotideCenter)
        {
            NucleotideCenter = ntCenter;
            NextNucleotide = nextNucleotideCenter;
            PreviousNucleotide = prevNucleotideCenter;
            UpdateVectors();
        }

        public void MoveBy(Point delta)
        {
            NucleotideCenter = new Point(NucleotideCenter.X + delta.X, NucleotideCenter.Y + delta.Y);
            UpdateVectors();
        }

        public void MoveNextNucleotideBy(Point delta)
        {
            NextNucleotide = new Point(NextNucleotide.X + delta.X, NextNucleotide.Y + delta.Y);
            UpdateVectors();
        }

        public void MoveNextNucleotideTo(Point location)
        {
            NextNucleotide = location;
            UpdateVectors();
        }

        public void MovePreviousNucleotideBy(Point delta)
        {
            PreviousNucleotide = new Point(PreviousNucleotide.X + delta.X, PreviousNucleotide.Y + delta.Y);
            UpdateVectors();
        }

        public void MovePreviousNucleotideTo(Point location)
        {
            PreviousNucleotide = location;
            UpdateVectors();
        }

        public Point NucleotideCenter { get; private set; }
        public Point NextNucleotide { get; private set; }
        public Point PreviousNucleotide { get; private set; }
        
        public double Distance { get; private set; }
        public double RayAngle { get; private set; }
        public Point Center { get; private set; }

        public double DistancePrevious { get; private set; }
        public double RayAnglePrevious { get; private set; }
        public Point CenterPrevious { get; private set; }

        private void UpdateVectors()
        {
            RayAngle = Math.PI + Math.Atan2((NucleotideCenter.Y - NextNucleotide.Y), (NucleotideCenter.X - NextNucleotide.X));
            Distance = Math.Sqrt(Math.Pow((NucleotideCenter.Y - NextNucleotide.Y), 2) + Math.Pow((NucleotideCenter.X - NextNucleotide.X), 2));
            double centerX = (NucleotideCenter.X + ((Distance / 2.0) * Math.Cos(RayAngle)));
            double centerY = (NucleotideCenter.Y + ((Distance / 2.0) * Math.Sin(RayAngle)));
            Center = new Point(centerX, centerY);

            RayAnglePrevious = Math.PI + Math.Atan2((PreviousNucleotide.Y - NucleotideCenter.Y), (PreviousNucleotide.X - NucleotideCenter.X));
            DistancePrevious = Math.Sqrt(Math.Pow((PreviousNucleotide.Y - NucleotideCenter.Y), 2) + Math.Pow((PreviousNucleotide.X - NucleotideCenter.X), 2));
            double centerXPrevious = (NucleotideCenter.X - ((DistancePrevious / 2.0) * Math.Cos(RayAnglePrevious)));
            double centerYPrevious = (NucleotideCenter.Y - ((DistancePrevious / 2.0) * Math.Sin(RayAnglePrevious))); 
        }
    }
}
